﻿<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" Title="IP地址屏蔽" %>

<script runat="server">
	protected void btnDeleteDeactiveIP_Click(object sender, EventArgs e)
	{
		using (TDataContext db = new TDataContext())
		{
			var q = from b in db.TIpBlocks
					where b.LastVisitTime < DateTime.Now.AddDays(-30)
					select b;

			db.TIpBlocks.DeleteAllOnSubmit(q);
			db.SubmitChanges();
		}

		ListView1.DataBind();
	}
</script>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
	<asp:LinqDataSource ID="LinqDataSource1" runat="server" 
		ContextTypeName="Xpus.YouYTube.Data.TDataContext" EnableDelete="True" 
		OrderBy="LastVisitTime desc" TableName="TIpBlocks">
	</asp:LinqDataSource>
	<asp:ListView ID="ListView1" runat="server" DataKeyNames="IpAddress" 
		DataSourceID="LinqDataSource1">
		<LayoutTemplate>
			<table runat="server">
				<tr runat="server">
					<td runat="server">
						<asp:Button ID="btnDeleteDeactiveIP" runat="server" Text="删除30内不再活跃的IP屏蔽" OnClick="btnDeleteDeactiveIP_Click" />
					</td>
				</tr>
				<tr runat="server">
					<td runat="server">
						<table ID="itemPlaceholderContainer" runat="server" border="0" style="">
							<tr runat="server" style="">
								<th runat="server"></th>
								<th runat="server">IP地址</th>
								<th runat="server">最后尝试访问时间</th>
							</tr>
							<tr ID="itemPlaceholder" runat="server">
							</tr>
						</table>
					</td>
				</tr>
				<tr runat="server">
					<td runat="server" style="">
						<asp:DataPager ID="DataPager1" runat="server">
							<Fields>
								<asp:NextPreviousPagerField ShowFirstPageButton="true" ShowNextPageButton="false" FirstPageText="第一页" PreviousPageText="上一页" />
								<asp:NumericPagerField />
								<asp:NextPreviousPagerField ShowPreviousPageButton="false" ShowLastPageButton="true" NextPageText="下一页" LastPageText="最后一页" />
							</Fields>
						</asp:DataPager>
					</td>
				</tr>
			</table>
		</LayoutTemplate>
		<EmptyDataTemplate>
			<table runat="server" style="">
				<tr>
					<td>暂无数据。</td>
				</tr>
			</table>
		</EmptyDataTemplate>
		<ItemTemplate>
			<tr style="">
				<td>
					<asp:LinkButton ID="DeleteButton" runat="server" CommandName="Delete" 
						Text="解除屏蔽" OnClientClick="return confirm('解除屏蔽后该IP的用户将可以继续发表评论等。该操作无法撤销，是否继续？')" />
				</td>
				<td>
					<asp:Label ID="IpAddressLabel" runat="server" Text='<%# Eval("IpAddress") %>' />
				</td>
				<td>
					<asp:Label ID="LastVisitTimeLabel" runat="server" 
						Text='<%# ((DateTime)Eval("LastVisitTime")).ToString("yyyy-MM-dd HH:mm:ss") %>' />
				</td>
			</tr>
		</ItemTemplate>
	</asp:ListView>
</asp:Content>

